window.onload = function()
{
	// alert("test!");//用来测试当前文件是否已经连接上HTML
	let userID = document.getElementById("userID");//元素定位到userID
	let password = document.getElementById("password");//元素定位到password
	let userID_error = document.getElementById("userID_error");//元素定位到userID_error
	let password_error = document.getElementById("password_error");//元素定位到password_error
	const RegglarExpression_userID = /^\d{8,}$/;//学号的正则 
    const RegglarExpression_password = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;//判断密码的正则表达式
	const form_action = document.getElementById("form_action");//定位到form表单
	const button_login = document.getElementById("login");//元素定位到表单提交按钮
	//当失去焦点时
	 userID.onblur = function()
	 {
		 let userID_value = userID.value;
		 userID_value = userID_value.trim(); // 去除前后空格
		 if(!RegglarExpression_userID.test(userID_value))
		 {
		 	userID_error.innerText="你输入的账号格式有误"; //在页面显示错误提示
			userID.style.border = "2px solid red";
			// userID_error.style.color = "red";
		 }
		 
	 }
	 //当获得焦点时
	 userID.onfocus = function ()
	 {
		 userID_error.innerText = "";//隐藏错误提示
		 userID.style.border = "2px solid #5dc235";
	 }
	 
	 password.addEventListener('blur',the_blur);//失去焦点时执行the_blur函数
	 function the_blur()
	 {
		 let password_value  = password.value;
		// password_value = password_value.trim();
		if(!RegglarExpression_password.test(password_value))
		{
			password_error.innerText = "你输入的密码格式有误";
			password.style.border = "2px solid red";
		}
	 }
	 
	 password.addEventListener("focusin",the_focusin);//当获得焦点时执行the_focusin。
	 function the_focusin()
	 {
		 password_error.innerText = "";//往网页中输出一个空文本
		 password.style.border = "2px solid #5dc235";
	 }
	 
	 button_login.addEventListener('click',form);
	 function form()
	 {
		 userID.focus();
		 userID.blur();
		 password.focus();
		 password.blur();
		 if(userID_error.innerText=="" && password_error.innerText == "")
		 {
			form_action.submit();
		 }
	 }
	 
	 //明天要做的事情
	 // 1.把表单的内容匹配正则才能提交 form.submit() 把sumbit改为button。 check
	 //2.用PHP写一个登陆界面，创建一个mysql数据库，用数据库的数据与用户提交的数据进行匹配。true即可登陆false则提示错误。网页的选项用ajax写，
	 // 3.完成明日早餐模块 尽快构思。
	 // @Parma 2020.12.13 Lam
	 
	
}